<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>宿舍信息</title>
    </head>
    <script>
        function but() {
            let dorm = document.querySelector("#dorm").value;
            let message;
            if (dorm === '1') {
                message = "13号楼"
            }
            else if (dorm === '2') {
                message = "14号楼"
            }
            else {
                alert("请选择对应宿舍")
                return;
            }
            let xhr = new XMLHttpRequest();
            xhr.open("post", "dorm.do");
            xhr.send(message);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    document.querySelector("#ajax_span").innerHTML = xhr.responseText;
                }
            }
        }
    </script>
    <body>
        <h3>宿舍信息展示页面</h3>
        <hr>
        <select name="dorm" id="dorm">
            <option value="0">--请选择--</option>
            <option value="1">13号楼</option>
            <option value="2">14号楼</option>
        </select>
        <input type="button" value="查询" onclick="but()">
        <br>
        <span id="ajax_span">宿舍信息展示</span>
        <hr>
        <a href="login.html">转跳到登录测试页面</a>
    </body>
</html>
